package com.gxa.javaserver.controller;

import com.gxa.javaserver.pojo.User;
import org.springframework.web.bind.annotation.*;

/**
 * @author:Teacher黄
 * @date:Created at 2020/06/02
 */
//@RestController
public class IndexController {


    /**
     * 测试方法
     * @return
     */
    @GetMapping("/index")
    public String index(){
        return "Hello 四川大学!";
    }


    /**
     * 测试@RequestMapping
     * @return
     */
    @RequestMapping(path = "/index2",method = RequestMethod.GET)
    public String index2(){
        return "Hello World!";
    }


    /**
     * 测试post请求
     * @return
     */
    @PostMapping("/index3")
    public String index3(@RequestParam(name = "myId",defaultValue = "9") Integer id){

        return "Hello Post!-"+id;
    }


    /**
     * 测试路径传参
     * @return
     */
    @PostMapping("/index4/{id}")
    public String index4(@PathVariable("id") Integer id){

        return "Hello Path:"+id;
    }


    /**
     * 测试接收对象
     * -- 普通的表单请求
     * @return
     */
    @PostMapping("/index5")
    public User index5(User user){
        return user;
    }

    /**
     * 测试接收JSON数据并注入对象
     * @return
     */
    @PostMapping("/index6")
    public User index6(@RequestBody User user){
        return user;
    }

}
